﻿#include "cTools.h"

CTools::CTools()
{

}

void CTools::exitProgram(){
    Sleep(40);
    exit(0);
}

QString CTools::fileDialog_saveFile(QString typeStr, QString defaultName){

    if(defaultName == ""){
        defaultName = QDateTime::currentDateTime().toString("yyyyMMddhhmmss.") + typeStr;
    }

    QString path="/path/to/default/"+defaultName;
    QString  wlkSavePath = QFileDialog::getSaveFileName(NULL, "保存", path, typeStr + QString("%1 files(*.%1)").arg(typeStr));
    if(wlkSavePath.isEmpty()&&wlkSavePath.isNull()){
        return "";
    }else{
        return wlkSavePath;
    }
}

QString CTools::fileDialog_openFile(QString typeStr, QString defaultName){
    return "";
}

double CTools::readDp(){

    QFile file("config.xml");
    bool isOpen = file.open(QIODevice::ReadOnly);
    if(isOpen){
        QTextStream filestream(&file);//QTextStream 与file关联
        QString str;
        while (filestream.atEnd()==false)
        {
            str = filestream.readLine();
            double dp = str.toDouble();
            if(dp > 0.2 && dp < 3){
                qDebug() << "读取到dp为";
                return dp;
            }
        }

    }else{
        qDebug() << "文件打开失败";
    }
    qDebug() << "未读取到dp，缺省为1";
    return 1;

}
